from datetime import datetime
from .base import BaseModel
from ..extensions.extensions import db

class UserRole(BaseModel):
    """用户角色关系表"""
    __tablename__ = 'user_roles'
    
    user_id = db.Column(db.Integer, nullable=False, comment='用户ID')
    role_id = db.Column(db.Integer, nullable=False, comment='角色ID')
    
    def to_dict(self):
        """转换为字典"""
        return {
            'id': self.id,
            'user_id': self.user_id,
            'role_id': self.role_id,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
            'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None
        } 